{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 问题描述：查询所有上市公司的五张财务表，2015-2020q2期间每个季度的所有财务数据，存储进自己的本地数据库中。 \n",
    "### 作业提交jupyter notebook中的ipynb代码文件,以及使用命令导出.sql或者.excel后缀文件，并且计算从下载到存储成功过程的耗时。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3975, 238)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = get_fundamentals(query(valuation,balance,cash_flow,income,indicator),date ='2020-10-15')\n",
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "list1 = []\n",
    "for i in range (15,21):\n",
    "    for j in range(1,5):\n",
    "        Date_years='20'+str(i)+'q'+str(j)\n",
    "        df = get_fundamentals(query(valuation,balance,cash_flow,income,indicator),statDate=Date_years)\n",
    "        list1.append(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "data1 = pd.concat(list1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(76569, 238)"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data1.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>code</th>\n",
       "      <th>pubDate</th>\n",
       "      <th>pe_ratio</th>\n",
       "      <th>turnover_ratio</th>\n",
       "      <th>pb_ratio</th>\n",
       "      <th>ps_ratio</th>\n",
       "      <th>pcf_ratio</th>\n",
       "      <th>capitalization</th>\n",
       "      <th>market_cap</th>\n",
       "      <th>circulating_cap</th>\n",
       "      <th>circulating_market_cap</th>\n",
       "      <th>day</th>\n",
       "      <th>pe_ratio_lyr</th>\n",
       "      <th>id.1</th>\n",
       "      <th>code.1</th>\n",
       "      <th>statDate</th>\n",
       "      <th>pubDate.1</th>\n",
       "      <th>statDate.1</th>\n",
       "      <th>cash_equivalents</th>\n",
       "      <th>settlement_provi</th>\n",
       "      <th>lend_capital</th>\n",
       "      <th>trading_assets</th>\n",
       "      <th>bill_receivable</th>\n",
       "      <th>account_receivable</th>\n",
       "      <th>advance_payment</th>\n",
       "      <th>insurance_receivables</th>\n",
       "      <th>reinsurance_receivables</th>\n",
       "      <th>reinsurance_contract_reserves_receivable</th>\n",
       "      <th>interest_receivable</th>\n",
       "      <th>dividend_receivable</th>\n",
       "      <th>other_receivable</th>\n",
       "      <th>bought_sellback_assets</th>\n",
       "      <th>inventories</th>\n",
       "      <th>non_current_asset_in_one_year</th>\n",
       "      <th>other_current_assets</th>\n",
       "      <th>total_current_assets</th>\n",
       "      <th>loan_and_advance</th>\n",
       "      <th>hold_for_sale_assets</th>\n",
       "      <th>hold_to_maturity_investments</th>\n",
       "      <th>...</th>\n",
       "      <th>other_composite_income</th>\n",
       "      <th>total_composite_income</th>\n",
       "      <th>ci_parent_company_owners</th>\n",
       "      <th>ci_minority_owners</th>\n",
       "      <th>id.4</th>\n",
       "      <th>code.4</th>\n",
       "      <th>statDate.6</th>\n",
       "      <th>pubDate.4</th>\n",
       "      <th>statDate.7</th>\n",
       "      <th>eps</th>\n",
       "      <th>adjusted_profit</th>\n",
       "      <th>operating_profit.1</th>\n",
       "      <th>value_change_profit</th>\n",
       "      <th>roe</th>\n",
       "      <th>inc_return</th>\n",
       "      <th>roa</th>\n",
       "      <th>net_profit_margin</th>\n",
       "      <th>gross_profit_margin</th>\n",
       "      <th>expense_to_total_revenue</th>\n",
       "      <th>operation_profit_to_total_revenue</th>\n",
       "      <th>net_profit_to_total_revenue</th>\n",
       "      <th>operating_expense_to_total_revenue</th>\n",
       "      <th>ga_expense_to_total_revenue</th>\n",
       "      <th>financing_expense_to_total_revenue</th>\n",
       "      <th>operating_profit_to_profit</th>\n",
       "      <th>invesment_profit_to_profit</th>\n",
       "      <th>adjusted_profit_to_profit</th>\n",
       "      <th>goods_sale_and_service_to_revenue</th>\n",
       "      <th>ocf_to_revenue</th>\n",
       "      <th>ocf_to_operating_profit</th>\n",
       "      <th>inc_total_revenue_year_on_year</th>\n",
       "      <th>inc_total_revenue_annual</th>\n",
       "      <th>inc_revenue_year_on_year</th>\n",
       "      <th>inc_revenue_annual</th>\n",
       "      <th>inc_operation_profit_year_on_year</th>\n",
       "      <th>inc_operation_profit_annual</th>\n",
       "      <th>inc_net_profit_year_on_year</th>\n",
       "      <th>inc_net_profit_annual</th>\n",
       "      <th>inc_net_profit_to_shareholders_year_on_year</th>\n",
       "      <th>inc_net_profit_to_shareholders_annual</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>62048194</td>\n",
       "      <td>002107.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>25.1318</td>\n",
       "      <td>0.9718</td>\n",
       "      <td>6.0326</td>\n",
       "      <td>4.7901</td>\n",
       "      <td>31.2792</td>\n",
       "      <td>5.772096e+04</td>\n",
       "      <td>46.4077</td>\n",
       "      <td>5.633258e+04</td>\n",
       "      <td>45.2914</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>48.4415</td>\n",
       "      <td>210675</td>\n",
       "      <td>002107.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>2021-01-21</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>4.944265e+08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>11658065.08</td>\n",
       "      <td>1.155118e+08</td>\n",
       "      <td>4.349017e+06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3121148.70</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.146434e+08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10543387.78</td>\n",
       "      <td>7.941668e+08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>3.967739e+07</td>\n",
       "      <td>3.811582e+07</td>\n",
       "      <td>1561574.28</td>\n",
       "      <td>356819</td>\n",
       "      <td>002107.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>2021-01-21</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>0.0660</td>\n",
       "      <td>3.664439e+07</td>\n",
       "      <td>4.340101e+07</td>\n",
       "      <td>-1.729578e+04</td>\n",
       "      <td>4.83</td>\n",
       "      <td>4.65</td>\n",
       "      <td>2.84</td>\n",
       "      <td>15.52</td>\n",
       "      <td>76.01</td>\n",
       "      <td>83.02</td>\n",
       "      <td>17.01</td>\n",
       "      <td>15.52</td>\n",
       "      <td>46.99</td>\n",
       "      <td>4.82</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>101.02</td>\n",
       "      <td>-0.04</td>\n",
       "      <td>96.14</td>\n",
       "      <td>116.40</td>\n",
       "      <td>27.23</td>\n",
       "      <td>160.34</td>\n",
       "      <td>17.07</td>\n",
       "      <td>-4.18</td>\n",
       "      <td>17.07</td>\n",
       "      <td>-4.18</td>\n",
       "      <td>-22.12</td>\n",
       "      <td>-36.73</td>\n",
       "      <td>-22.11</td>\n",
       "      <td>-25.31</td>\n",
       "      <td>-13.16</td>\n",
       "      <td>-23.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>62047946</td>\n",
       "      <td>300617.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>44.4240</td>\n",
       "      <td>3.7924</td>\n",
       "      <td>7.1133</td>\n",
       "      <td>13.1091</td>\n",
       "      <td>181.2950</td>\n",
       "      <td>1.293436e+04</td>\n",
       "      <td>64.3226</td>\n",
       "      <td>6.468331e+03</td>\n",
       "      <td>32.1670</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>101.1100</td>\n",
       "      <td>210676</td>\n",
       "      <td>300617.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>2021-01-27</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>1.423751e+08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.875939e+08</td>\n",
       "      <td>1358000.49</td>\n",
       "      <td>2.809408e+08</td>\n",
       "      <td>1.523321e+07</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8818321.44</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.233000e+08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>17731270.68</td>\n",
       "      <td>9.193060e+08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6.986942e+06</td>\n",
       "      <td>5.202761e+06</td>\n",
       "      <td>1784180.62</td>\n",
       "      <td>357239</td>\n",
       "      <td>300617.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>2021-01-27</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>0.0402</td>\n",
       "      <td>2.201691e+06</td>\n",
       "      <td>2.033351e+07</td>\n",
       "      <td>1.827487e+06</td>\n",
       "      <td>0.57</td>\n",
       "      <td>0.24</td>\n",
       "      <td>0.57</td>\n",
       "      <td>4.49</td>\n",
       "      <td>47.18</td>\n",
       "      <td>86.94</td>\n",
       "      <td>9.07</td>\n",
       "      <td>4.49</td>\n",
       "      <td>11.68</td>\n",
       "      <td>12.17</td>\n",
       "      <td>0.16</td>\n",
       "      <td>145.33</td>\n",
       "      <td>13.06</td>\n",
       "      <td>42.32</td>\n",
       "      <td>78.92</td>\n",
       "      <td>-1.33</td>\n",
       "      <td>-10.20</td>\n",
       "      <td>32.38</td>\n",
       "      <td>-10.71</td>\n",
       "      <td>32.38</td>\n",
       "      <td>-10.71</td>\n",
       "      <td>-32.28</td>\n",
       "      <td>-80.29</td>\n",
       "      <td>-60.79</td>\n",
       "      <td>-88.69</td>\n",
       "      <td>-70.48</td>\n",
       "      <td>-91.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>62047245</td>\n",
       "      <td>002072.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>24.9807</td>\n",
       "      <td>0.5234</td>\n",
       "      <td>28.4101</td>\n",
       "      <td>-20.9990</td>\n",
       "      <td>291.0205</td>\n",
       "      <td>1.760000e+04</td>\n",
       "      <td>7.8848</td>\n",
       "      <td>1.529191e+04</td>\n",
       "      <td>6.8508</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>92.3151</td>\n",
       "      <td>210678</td>\n",
       "      <td>002072.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>2021-01-30</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>1.589689e+07</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.003248e+07</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.838556e+07</td>\n",
       "      <td>3.390046e+07</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24752655.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10058944.98</td>\n",
       "      <td>1.730270e+08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-2.066311e+08</td>\n",
       "      <td>-2.066556e+08</td>\n",
       "      <td>24477.10</td>\n",
       "      <td>357528</td>\n",
       "      <td>002072.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>2021-01-30</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>-1.1742</td>\n",
       "      <td>-2.045305e+08</td>\n",
       "      <td>1.905791e+05</td>\n",
       "      <td>NaN</td>\n",
       "      <td>273.45</td>\n",
       "      <td>270.64</td>\n",
       "      <td>-40.61</td>\n",
       "      <td>-3725.58</td>\n",
       "      <td>99.90</td>\n",
       "      <td>96.56</td>\n",
       "      <td>-3674.02</td>\n",
       "      <td>-3725.58</td>\n",
       "      <td>0.87</td>\n",
       "      <td>30.80</td>\n",
       "      <td>63.84</td>\n",
       "      <td>-0.09</td>\n",
       "      <td>NaN</td>\n",
       "      <td>98.97</td>\n",
       "      <td>177.66</td>\n",
       "      <td>21.29</td>\n",
       "      <td>619.65</td>\n",
       "      <td>109.48</td>\n",
       "      <td>2.22</td>\n",
       "      <td>109.48</td>\n",
       "      <td>2.22</td>\n",
       "      <td>-7609.25</td>\n",
       "      <td>-17200.73</td>\n",
       "      <td>-854.27</td>\n",
       "      <td>-69926.97</td>\n",
       "      <td>-854.36</td>\n",
       "      <td>-83437.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>62048959</td>\n",
       "      <td>000001.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>13.9148</td>\n",
       "      <td>0.4764</td>\n",
       "      <td>1.2994</td>\n",
       "      <td>2.4763</td>\n",
       "      <td>2.7943</td>\n",
       "      <td>1.940592e+06</td>\n",
       "      <td>3753.1045</td>\n",
       "      <td>1.940575e+06</td>\n",
       "      <td>3753.0725</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>13.3112</td>\n",
       "      <td>210680</td>\n",
       "      <td>000001.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>2021-02-02</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>2.839820e+11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.099600e+10</td>\n",
       "      <td>3.112700e+11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9.531400e+10</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.610841e+12</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>-3.500000e+08</td>\n",
       "      <td>6.180000e+09</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>357660</td>\n",
       "      <td>000001.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>2021-02-02</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>0.3365</td>\n",
       "      <td>6.524000e+09</td>\n",
       "      <td>6.795000e+09</td>\n",
       "      <td>1.132000e+09</td>\n",
       "      <td>1.81</td>\n",
       "      <td>1.80</td>\n",
       "      <td>0.15</td>\n",
       "      <td>17.66</td>\n",
       "      <td>NaN</td>\n",
       "      <td>78.40</td>\n",
       "      <td>21.60</td>\n",
       "      <td>17.66</td>\n",
       "      <td>NaN</td>\n",
       "      <td>34.06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>85.71</td>\n",
       "      <td>14.28</td>\n",
       "      <td>99.91</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-126.72</td>\n",
       "      <td>-689.61</td>\n",
       "      <td>5.65</td>\n",
       "      <td>-3.29</td>\n",
       "      <td>5.65</td>\n",
       "      <td>-3.29</td>\n",
       "      <td>43.22</td>\n",
       "      <td>-29.10</td>\n",
       "      <td>42.76</td>\n",
       "      <td>-25.11</td>\n",
       "      <td>42.76</td>\n",
       "      <td>-25.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>62047104</td>\n",
       "      <td>002984.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>17.7589</td>\n",
       "      <td>18.8584</td>\n",
       "      <td>3.0053</td>\n",
       "      <td>3.4826</td>\n",
       "      <td>13.7178</td>\n",
       "      <td>6.496689e+04</td>\n",
       "      <td>164.9509</td>\n",
       "      <td>6.900000e+03</td>\n",
       "      <td>17.5191</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>22.2688</td>\n",
       "      <td>210681</td>\n",
       "      <td>002984.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>2021-02-02</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>1.620292e+09</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.509748e+08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.620232e+08</td>\n",
       "      <td>1.110463e+08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>77574066.56</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.936788e+08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>36063610.02</td>\n",
       "      <td>3.256794e+09</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>-9.458782e+07</td>\n",
       "      <td>1.699238e+08</td>\n",
       "      <td>1.699238e+08</td>\n",
       "      <td>2.78</td>\n",
       "      <td>357661</td>\n",
       "      <td>002984.XSHE</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>2021-02-02</td>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>0.4071</td>\n",
       "      <td>3.035889e+08</td>\n",
       "      <td>3.004627e+08</td>\n",
       "      <td>-2.046650e+06</td>\n",
       "      <td>4.79</td>\n",
       "      <td>5.50</td>\n",
       "      <td>3.41</td>\n",
       "      <td>22.74</td>\n",
       "      <td>31.54</td>\n",
       "      <td>74.16</td>\n",
       "      <td>26.26</td>\n",
       "      <td>22.74</td>\n",
       "      <td>-3.08</td>\n",
       "      <td>4.31</td>\n",
       "      <td>0.16</td>\n",
       "      <td>113.94</td>\n",
       "      <td>-0.78</td>\n",
       "      <td>114.77</td>\n",
       "      <td>122.29</td>\n",
       "      <td>39.58</td>\n",
       "      <td>153.20</td>\n",
       "      <td>-2.60</td>\n",
       "      <td>-16.87</td>\n",
       "      <td>-2.60</td>\n",
       "      <td>-16.87</td>\n",
       "      <td>40.42</td>\n",
       "      <td>-12.11</td>\n",
       "      <td>24.30</td>\n",
       "      <td>-20.14</td>\n",
       "      <td>24.30</td>\n",
       "      <td>-20.14</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         id                  ...                  inc_net_profit_to_shareholders_annual\n",
       "0  62048194                  ...                                                 -23.82\n",
       "1  62047946                  ...                                                 -91.55\n",
       "2  62047245                  ...                                              -83437.29\n",
       "3  62048959                  ...                                                 -25.11\n",
       "4  62047104                  ...                                                 -20.14\n",
       "\n",
       "[5 rows x 238 columns]"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "df2 = get_fundamentals(query(valuation,balance,cash_flow,income,indicator),statDate = '2020q1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "df3 = get_fundamentals(query(valuation,balance,cash_flow,income,indicator),statDate = '2020q2')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time used: 41.64649800000001\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "start = time.clock()\n",
    "\n",
    "list1 = []\n",
    "for i in range (15,20):\n",
    "    for j in range(1,5):\n",
    "        Date_years='20'+str(i)+'q'+str(j)\n",
    "        df = get_fundamentals(query(valuation,balance,cash_flow,income,indicator),statDate=Date_years)\n",
    "        list1.append(df)\n",
    "data1 = pd.concat(list1)   \n",
    "data2 = get_fundamentals(query(valuation,balance,cash_flow,income,indicator),statDate = '2020q1')\n",
    "data3 = get_fundamentals(query(valuation,balance,cash_flow,income,indicator),statDate = '2020q2')\n",
    "df =pd.concat([data1,data2,data3],axis = 0)\n",
    "df.to_csv('data.csv')\n",
    "\n",
    "elapsed = (time.clock()-start)\n",
    "print(\"Time used:\",elapsed)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(72521, 238)"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "MarkDown菜单",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
